package com.gitee.zycra.union.api.manager;

import com.gitee.zycra.union.api.common.model.ApiInterfaceCase;
import com.gitee.zycra.union.api.common.param.AddInterfaceCaseParam;
import com.gitee.zycra.union.api.common.param.UpdateInterfaceCaseParam;
import com.gitee.zycra.union.api.common.util.IdGenerator;
import com.gitee.zycra.union.api.common.vo.InterfaceCaseVO;
import com.gitee.zycra.union.api.dao.ApiInterfaceCaseDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author zycra
 */
@Component
public class ApiInterfaceCaseManager {

    @Autowired
    private ApiInterfaceCaseDao apiInterfaceCaseDao;

    @Autowired
    private IdGenerator idGenerator;

    /**
     * 添加接口
     *
     * @param addInterfaceCaseParam 添加参数
     * @return 影响行数
     */
    public int addInterfaceCase(AddInterfaceCaseParam addInterfaceCaseParam) {
        ApiInterfaceCase apiInterfaceCase = AddInterfaceCaseParam.convertToApiInterfaceCase(addInterfaceCaseParam);
        apiInterfaceCase.setId(idGenerator.nextId());
        return apiInterfaceCaseDao.insert(apiInterfaceCase);
    }

    /**
     * 更新接口期望
     *
     * @param updateInterfaceCaseParam 更新参数
     * @return 影响行数
     */
    public int updateInterfaceCase(UpdateInterfaceCaseParam updateInterfaceCaseParam) {
        ApiInterfaceCase apiInterface = UpdateInterfaceCaseParam.convertToApiInterfaceCase(updateInterfaceCaseParam);
        return apiInterfaceCaseDao.updateById(apiInterface);
    }

    /**
     * 删除接口期望
     *
     * @param id 接口期望ID
     * @return 影响行数
     */
    public int deleteInterfaceCase(Long id) {
        return apiInterfaceCaseDao.updateToDelete(id);
    }

    /**
     * 查询接口期望
     *
     * @param interfaceId 接口ID
     * @return 查询结果
     */
    public List<InterfaceCaseVO> selectByInterfaceId(Long interfaceId) {
        return apiInterfaceCaseDao.selectByInterfaceId(interfaceId);
    }
}
